import Button from "components/Base/Button";
import Icon from "components/Base/Icon";
import DataTable from "components/Base/DataTable";
import Image from "components/Base/Image";
import {orderDict} from "../../../../models/OrderStatus";
import {Tag} from "antd";

export default (self) => [

  {
    title: '订单id',
    name: 'orderId',
    tableItem: {
    },
    formItem: {
      type: 'hidden',
    }
  },
  {
    title: '金额',
    name: 'payment',
    tableItem: {
    },
  },
  {
    title: '支付类型',
    name: 'paymentType',
    dict: [
      { code: 'ONLINE', codeName: '在线支付' },
      { code: 'OFFLINE', codeName: '货到付款' },
    ],
    tableItem: {
    },
  },
  {
    title: '邮费',
    name: 'postFee',
    tableItem: {
    },
  },
  {
    title: '订单状态',
    name: 'orderStatus',
    // dict: orderDict,
    tableItem: {
      render: (text, record) => {
        return <Tag color={record.orderStatusColor}>{text}</Tag>
      }
    },
  },
  {
    title: '用户昵称',
    name: 'nickName',
    tableItem: {
    },
  },
  {
    title: '商家名字',
    name: 'sellerName',
    tableItem: {
    },
  },
  {
    title: '付款时间',
    name: 'paymentTime',
    tableItem: {
    },
  },

  {
    title: '物流公司',
    name: 'shippingName',
    formItem: {
      rules: [
        {
          required: true,
          message: '请选择物流公司'
        }
      ],

      showSearch: true,
      type: 'select',
      loading: self.getAll("shipper").loading,  // 加载状态
      onDropdownVisibleChange : (visible) =>{
        if (visible){
          self.dispatch({
            type: `shipper/getAll`,
          })
        }
      },
    },
    dict: self.getAll("shipper").dict,
  },


  {
    title: '物流单号',
    name: 'shippingCode',
    formItem: {
      rules: [
        {
          required: true,
          message: '请输入物流单号'
        }
      ]
    },
  },

  {
    title: '操作',
    tableItem: {
      width: 180,
      align: 'center',
      render: (text, record) => {

        const {orderId, orderStatus} = record;
        var path = `/detail/Order/${orderId}`;

        const disable = orderStatus!='已付款';

        return (
          <DataTable.Oper>
            {
              <Button tooltip="发货" disabled={disable} onClick={e => self.onUpdate(record)}>
                <Icon type="upload" />
              </Button>
            }
            {/*<Button tooltip="删除" onClick={e => self.onDelete(record)}>*/}
            {/*  <Icon type="trash"/>*/}
            {/*</Button>*/}
            <Button tooltip="详情" onClick={e => self.jump(path)}>
              <Icon antd={true} type="snippets"/>
            </Button>
          </DataTable.Oper>
        );
      }
    }
  }
]
